<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增菜单')" />
</head>
<body class="white-bg">
<form class="form-horizontal m" id="form-book-add">
    <input name="category"  type="hidden"  id="treeId"/>
    <div class="form-group">
        <label class="col-sm-3 control-label is-required">名字：</label>
        <div class="col-sm-8">
            <input class="form-control" type="text" name="name" id="name" required>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label is-required">作者：</label>
        <div class="col-sm-8">
            <input class="form-control" type="text" name="author" id="author" required>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label">状态：</label>
        <div class="col-sm-8">
            <input class="form-control" type="text" id="status" name="status">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label">分类：</label>
        <div class="col-sm-8">
            <div class="input-group">
                <input class="form-control" type="text" name="categoryName" onclick="selectCategoryTree()" id="treeName" >
                <span class="input-group-addon"><i class="fa fa-search"></i></span>
            </div>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-3 control-label">字数：</label>
        <div class="col-sm-8">
            <input class="form-control" type="text" id="cssClass" name="cssClass">
        </div>
    </div>


</form>

<th:block th:include="include :: footer" />
<script type="text/javascript">
		var prefix = ctx + "book/manage";

		$("#form-book-add").validate({
			rules:{
				dictSort:{
					digits:true
				},
			},
			focusCleanup: true
		});

		function submitHandler() {
		console.log("submit..");
	        if ($.validate.form()) {
	        console.log($('#form-book-add').serialize());
	        	$.operate.save(prefix + "/add", $('#form-book-add').serialize());
	        }
	        else
	        {
	            console.log("validate fail");
	        }
	    }


	    /* 选择分类树 */
        function selectCategoryTree() {
        	var categoryId = $.common.isEmpty($("#treeId").val()) ? "100" : $("#treeId").val();
            var url = ctx + "book/category/selectCategoryTree/" + categoryId;
		    var options = {
				title: '选择分类',
				width: "380",
				url: url,
				callBack: doSubmit
			};
			$.modal.openOptions(options);
		}
		function doSubmit(index, layero){
			var tree = layero.find("iframe")[0].contentWindow.$._tree;
			var body = $.modal.getChildFrame(index);
   			$("#treeId").val(body.find('#treeId').val());
   			$("#treeName").val(body.find('#treeName').val());
   			console.log("treeId:"+$("#treeId").val());
   			console.log("treeName:"+$("#treeName").val());

   			$.modal.close(index);
		}
	</script>

</body>
</html>